package com.example.demo.hutool.redis.monitor;


import com.example.demo.hutool.BitMap;
import com.example.demo.hutool.redis.RedisTypeTest;
import org.apache.lucene.util.RamUsageEstimator;
import org.springframework.util.SerializationUtils;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisMonitor;
import redis.clients.jedis.JedisPool;


/**
 * 入口类
 *
 * @author 吕桂强
 * @version 创建时间：2012-3-28 下午12:12:41
 * @email larry.lv.word@gmail.com
 */
public class jedis_demo {
    static final int hash(String key) {
        long index = Math.abs((long) (key.hashCode() % 1999999999));
        byte[] serialize = SerializationUtils.serialize("user:1");
        return (int) index;

    }

    public static void main(String[] args) {
//        long start = System.currentTimeMillis();
//        for (int i = 0; i <10000000 ; i++) {
//            byte[] serialize = SerializationUtils.serialize("user:1"+i);
//        }
//        long end = System.currentTimeMillis();
//        System.out.println(end-start);

        JedisPool jedisPool = RedisTypeTest.getJedisPool();
//        Jedis resource = jedisPool.getResource();
//                byte[] serialize = SerializationUtils.serialize("user:1");
//        String s = resource.get("user:1");
//        System.out.println();

//        resource.set(serialize,serialize);


        //设置监控
        new Thread(new Runnable() {
            @Override
            public void run() {

                Jedis jedis = jedisPool.getResource();
                jedis.monitor(new JedisMonitor() {
                    @Override
                    public void onCommand(String command) {
                        System.out.println("#monitor: " + command);
                    }
                });
            }
        }).start();


    }


}